package nil.ed.simulator.request.client.activity;

import com.google.inject.Inject;
import nil.ed.simulator.request.enums.ActivityGroup;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lidelin.
 */
public class ActivityRepo {

    private Map<ActivityGroup, List<IActivity>> activityMap;

    @Inject
    public void setActivities(Set<IActivity> activities) {
        this.activityMap = activities.stream().collect(Collectors.groupingBy(IActivity::getGroup, Collectors.collectingAndThen(Collectors.toList(), ls -> {
            ls.sort(Comparator.comparing(IActivity::getSort));
            return ls;
        })));
    }

    public List<IActivity> getActivities(ActivityGroup group) {
        return activityMap.getOrDefault(group, Collections.emptyList());
    }

}
